package com.tsunami.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.tsunami.base.entity.Entity;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


/**
 * @Classname MyMetaObjectHandler
 * @Description TODO mybtis-plus 自动填充时间
 * @Date 2021-06-11 16:36
 * @Created by lx
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ……");
        this.strictInsertFill(metaObject,Entity.CREATE_TIME, LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject, Entity.UPDATE_TIME, LocalDateTime.class,LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ……");

        this.strictUpdateFill(metaObject,Entity.UPDATE_TIME, LocalDateTime.class,LocalDateTime.now());
    }


}
